<template>
  <div class="index">
    <div class="left">
      <h2>酒店管理系统</h2>
      <el-menu
          router
          active-text-color="#ffd04b"
          background-color="#142334"
          class="el-menu-vertical-demo"
          default-active="2"
          text-color="#fff"
      >
        <el-sub-menu index="1">
          <template #title>
            <el-icon><User /></el-icon>
            <span>账户管理</span>
          </template>
          <el-menu-item index="/role">角色管理</el-menu-item>
          <el-menu-item index="/user">用户管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="2">
          <template #title>
            <el-icon><OfficeBuilding /></el-icon>
            <span>客房管理</span>
          </template>
          <el-menu-item index="/roomtype">房型管理</el-menu-item>
          <el-menu-item index="/room">房间管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon><Dish /></el-icon>
            <span>客户管理</span>
          </template>
          <el-menu-item index="/livein">入住用户</el-menu-item>
          <el-menu-item index="/order">客户订单</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
          <template #title>
            <el-icon><Edit /></el-icon>
            <span>系统管理</span>
          </template>
          <el-menu-item index="/menu">菜单管理</el-menu-item>
          <el-menu-item index="/dictionary">字典管理</el-menu-item>
        </el-sub-menu>

      </el-menu>
    </div>
    <div class="right">
      <div class="top">
        <el-menu
            router
            :ellipsis="false"
            class="el-menu-demo"
            mode="horizontal"
            background-color="#142334"
            text-color="#fff"
            active-text-color="#ffd04b"
        >
          <el-menu-item index="/index">
            <el-icon><HomeFilled /></el-icon>首页
          </el-menu-item>
          <el-menu-item index="/mail">
            <el-icon><Promotion /></el-icon>邮箱
          </el-menu-item>
          <el-menu-item index="message">
            <el-icon><Comment /></el-icon>消息
          </el-menu-item>
          <el-sub-menu index="">
            <template #title>
              <el-icon><Avatar /></el-icon>管理员
            </template>
            <el-menu-item index="/mine">个人中心</el-menu-item>
            <el-menu-item index="/setpwd">修改密码</el-menu-item>
            <el-menu-item index="" @click="exit">退出系统</el-menu-item>

          </el-sub-menu>

        </el-menu>
      </div>
      <div class="content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {onMounted} from 'vue'
//退出系统弹出框
import { ElMessageBox } from 'element-plus'
//导入图标
import {User, OfficeBuilding, Dish, Edit,HomeFilled,Promotion,Comment,Avatar} from '@element-plus/icons-vue'
//导入路由
import {useRouter} from 'vue-router'
import userUser from '../store/user.ts'
let userStore=userUser()
let router=useRouter()

//退出系统
let exit=()=>{
  ElMessageBox.confirm(
      '确定退出系统吗?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(() => {
        userStore.clearUser()
        router.push('/')
      })
      .catch(() => {
      })
}

onMounted(()=>{
  if(!userStore.user.msg){
    router.push('/')
  }
})
</script>

<style scoped lang="scss">
.index{
  width: 100vw;
  height:100vh;
  display:flex;
  .left{
    width:200px;
    background-color: #142334;
    color:white;
    .el-menu{
      border-right: none;
    }
    h2{
      font-size: 25px;
      text-align: center;
      height: 60px;
      line-height: 60px;
    }
  }
  .right{
    flex:1;
    display:flex;
    flex-direction: column;
    .top{
      height:60px;
      background-color: #142334;
      color:white;
      display: flex;
      justify-content: flex-end;
      .el-menu{
        border-bottom: none;
      }
    }
    .content{
      flex:1;
      padding: 5px;
    }
  }
}
</style>